﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Obligatorio.DataAccess;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TotalComprasWS : System.Web.Services.WebService {

    public TotalComprasWS () {
    }

    [WebMethod]
    public string getTotalCompras(String dateInit, string dateEnd, string branchId) {
        using (ObligatorioDotNetEntities data = new ObligatorioDotNetEntities())
        {
            short? branch = null;
            if (branchId.Equals("null"))
            {
                branch = null;
            }
            else 
            {
                branch = short.Parse(branchId);
            }
            List<SP_GetPruchasesByPeriod_Result> compras = data.SP_GetPruchasesByPeriod(DateTime.Parse(dateInit), DateTime.Parse(dateEnd), branch).ToList();

            if (compras != null)
            {
                System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
                new System.Web.Script.Serialization.JavaScriptSerializer();
                return oSerializer.Serialize(compras);
            }

            return "";
        }
    }
    
}
